#pragma once

#include <cstring>
#include <set>

namespace PC2
{


enum TransTypeEnum : uint32_t
{
	EnumEcho = 0,
	EnumPrepareRequest = 1,
	EnumPrepareOKResponse = 2,
	EnumPrepareRejectResponse = 3,
	EnumCommitRequest = 4,
	EnumAbortRequest = 5,
	EnumCommitAck = 6,
	EnumAbortAck = 7,
	EnumDecisionRequest = 8

};

class Trans
{
public:
	uint32_t m_TransId;
	uint32_t m_Size;
	uint32_t m_Type;
	uint32_t m_NodeId;

public:
	void AppendData(char const* apData, uint32_t aLen)
	{
		char* lpDest = (char*)(this + 1);
		memcpy(lpDest, apData, aLen);
		m_Size = sizeof(Trans) + aLen;
	}
};

class NodesHeader
{
public:
	uint32_t m_Size;
	void WriteParts(std::set<uint32_t>* apRelatedNode)
	{
		m_Size = apRelatedNode->size() * sizeof(uint32_t) + sizeof(uint32_t);
		char* lpData = (char*)this + sizeof(uint32_t);
		for (auto it = apRelatedNode->begin(); it != apRelatedNode->end(); it++)
		{
			*(uint32_t*)lpData = *it;
			lpData += sizeof(uint32_t);
		}
	}

	void ReadParts(std::set<uint32_t>* apRelatedNode)
	{
		char* lpMAX = (char*)this + m_Size;
		for (char* lpData = (char*)this + sizeof(uint32_t);lpData <lpMAX;lpData += sizeof(uint32_t))
		{
			apRelatedNode->insert(*(uint32_t*)lpData);
		}
	}

	void GetNextPointer(char const*& apData)
	{
		apData = (char*)this + m_Size;
	}
};



}